package behavioral_pattern.observer_pattern.subject;

import behavioral_pattern.observer_pattern.observer.Observer;

import java.util.ArrayList;
import java.util.List;

/*
 * @Author xuhj
 * @Description 抽象主题
 * @Date 9:54 下午 2022/1/4
 * @Param
 * @return
 **/
public abstract class Subject {
    public List<Observer> observerList = new ArrayList<>();
    private int state;

    // 注册观察着方法
    public void add(Observer observer){
        observerList.add(observer);
    }
    //移除观察者
    public void removeObserver(Observer observer){
        observerList.remove(observer);
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();

    }
    public abstract void notifyAllObservers();
}
